package com.fullstuck.service.impl;

import com.fullstuck.dao.User;
import com.fullstuck.dao.impl.UserDaoImpl;
import com.fullstuck.service.UserService;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 * 依赖注入
 */
public class UserServiceimpl implements UserService {

    //通过set方法注入UserDao
    //通过构造器注入UserDao
    private UserDaoImpl userDaoimpl;
    //设置set方法
//    public void setUserDaoimpl(UserDaoImpl userDaoimpl) {
//        this.userDaoimpl = userDaoimpl;
//    }
    //有参构造
    public UserServiceimpl(UserDaoImpl userDaoimpl) {
        this.userDaoimpl = userDaoimpl;
    }

    //通过set方法 和 .xml文件获取的 userDaoimpl,实现speak() 方法
    public void eat() {
          userDaoimpl.speak();

        //通过Spring 获取依赖注入
//        ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
//        User userdao = (User) context.getBean("userdao");
//        userdao.speak();
    }
}
